package home.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.LayoutHelper;
import com.alibaba.android.vlayout.layout.SingleLayoutHelper;

import net.ck.hzq.R;

import java.util.ArrayList;
import java.util.List;

import widget.ADEnity;
import widget.AudioTextView;

/**
 * by BF00233 on 2018/12/10.
 */
public class TopLineAdapter extends DelegateAdapter.Adapter<TopLineAdapter.TopLineVH> {

    private final Context mContext;
    private List<ADEnity> mText = new ArrayList<>();

    public TopLineAdapter(Context context) {
        mContext = context;
    }

    public void setData(List<ADEnity> text) {
        mText.clear();
        mText = text;
        notifyDataSetChanged();
    }

    @Override
    public LayoutHelper onCreateLayoutHelper() {
        return new SingleLayoutHelper();
    }

    @NonNull
    @Override
    public TopLineVH onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new TopLineVH(LayoutInflater.from(mContext).inflate(R.layout.item_home_top_line, viewGroup, false));
    }

    @Override
    public void onBindViewHolder(@NonNull TopLineVH holder, int i) {
        if (mText.size() == 0) {
            return;
        }
        holder.text.setFrontColor(0xFFFFFFFF);
        holder.text.setBackColor(0xFF383838);
        holder.text.setmInterval(1000);
        holder.text.setmDuration(2);
        holder.text.setmTexts(mText);
        holder.text.setOnClickLitener(new AudioTextView.onClickLitener() {
            @Override
            public void onClick() {

            }
        });
//        holder.text.setSelected(true);
//        holder.text.setText(mText);
    }

    @Override
    public int getItemCount() {
        return 1;
    }

    class TopLineVH extends RecyclerView.ViewHolder {
        private AudioTextView text;

        TopLineVH(@NonNull View itemView) {
            super(itemView);
            text = itemView.findViewById(R.id.fragment_audio_text);
        }
    }

    private int mChildCount = 0;
}
